import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
// import app from './modules/app'
// import settings from './modules/settings'
// import user from './modules/user'

Vue.use(Vuex)

// require.context: 可以加载导入指定的目录下所有的指定的文件
const req = require.context('./modules', false, /\.js$/)

console.log(req.keys(), 'vuex中req.keys')
const mName = req
  .keys()
  .map((item) => item.split('./')[1])
  .map((item) => item.split('.js')[0])

const mModele = req.keys().map(req)

const obj = {}

mName.forEach((item, index) => {
  obj[item] = mModele[index].default
})
console.log(obj, 'obj')

const store = new Vuex.Store({
  modules: obj,
  getters
})

export default store
